#!/usr/bin/env perl
require 5.008;
use warnings;
use strict;

unshift(@INC, '.');
require qpdf_test_helpers;

chdir("qpdf") or die "chdir testdir failed: $!\n";

require TestDriver;

cleanup();

my $td = new TestDriver('preserve-unref');

my $n_tests = 6;

$td->runtest("drop unused objects",
             {$td->COMMAND => "qpdf --static-id unreferenced-objects.pdf a.pdf"},
             {$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check output",
             {$td->COMMAND => "qpdf-test-compare a.pdf unreferenced-dropped.pdf"},
             {$td->FILE => "unreferenced-dropped.pdf", $td->EXIT_STATUS => 0});
$td->runtest("keep unused objects",
             {$td->COMMAND => "qpdf --static-id --preserve-unreferenced" .
                  " unreferenced-objects.pdf a.pdf"},
             {$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check output",
             {$td->COMMAND => "qpdf-test-compare a.pdf unreferenced-preserved.pdf"},
             {$td->FILE => "unreferenced-preserved.pdf", $td->EXIT_STATUS => 0});
$td->runtest("keep unused objects (C)",
             {$td->COMMAND =>
                  "qpdf-ctest 21 unreferenced-objects.pdf '' a.pdf"},
             {$td->STRING => "C test 21 done\n", $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);
$td->runtest("check output",
             {$td->COMMAND => "qpdf-test-compare a.pdf unreferenced-preserved.pdf"},
             {$td->FILE => "unreferenced-preserved.pdf", $td->EXIT_STATUS => 0});
cleanup();
$td->report($n_tests);
